<#include "/common/layout.html">
<@body>
<div class="content">
	<form id="storageForm" class="form-horizontal">
		<div class="box-body">
			<div class="form-group">
				<label class="col-sm-3 control-label">存储类型：</label>
				<div class="col-sm-9">
					<label class="radio-box">
						<input class="minimal" type="radio" ${(storageConfig.type == 0)?string('checked','')} name="type" value="0" require=""> 本地
					</label>
					<label class="radio-box">
						<input class="minimal" type="radio" ${(storageConfig.type == 1)?string('checked','')}  name="type" value="1" require=""> 七牛云
					</label>
					<label class="radio-box">
						<input class="minimal" type="radio" ${(storageConfig.type == 2)?string('checked','')}  name="type" value="2" require=""> 阿里云
					</label>
					<label class="radio-box">
						<input class="minimal" type="radio" ${(storageConfig.type == 3)?string('checked','')}  name="type" value="3" require=""> 腾讯云
					</label>
				</div>
			</div>
			<div id="local-form" class="${(storageConfig.type == 0)?string('','display-none')}">
				<div class="form-group">
					<div class="col-sm-3  control-label">文件服务器域名：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.localDomain}" name="localDomain" placeholder="本地文件服务器域名" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3  control-label">文件存储路径：</div>
					<div class="col-sm-9">
						<p>文件将保存在用户目录workDir的file下${workDir}file</p>
					</div>
				</div>
			</div>
			<div id="qiniu-form" class="${(storageConfig.type == 1)?string('','display-none')}">
				<div class="form-group">
					<label class="col-sm-3  control-label">文件服务器域名：</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.qiniuDomain}" name="qiniuDomain" require="必填项" placeholder="七牛云绑定的域名">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3  control-label">路径前缀：</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.qiniuPrefix}" name="qiniuPrefix" require="必填项" placeholder="不设置默认为空">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3  control-label">AccessKey：</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.qiniuAccessKey}" name="qiniuAccessKey" require="必填项" placeholder="七牛云AccessKey">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3  control-label">SecretKey：</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.qiniuSecretKey}" name="qiniuSecretKey" require="必填项" placeholder="七牛云SecretKey">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-3  control-label">BucketName：</label>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.qiniuBucketName}" name="qiniuBucketName" require="必填项" placeholder="七牛云BucketName">
					</div>
				</div>
			</div>
			<div id="ali-form" class=" ${(storageConfig.type == 2)?string('','display-none')}">
				<div class="form-group">
					<div class="col-sm-3  control-label">文件服务器域名：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.aliyunDomain}" name="aliyunDomain" placeholder="阿里云绑定的域名" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3  control-label">路径前缀：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.aliyunPrefix}" name="aliyunPrefix" placeholder="不设置默认为空" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3  control-label">EndPoint：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.aliyunEndPoint}" name="aliyunEndPoint" placeholder="阿里云EndPoint" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3  control-label">AccessKeyId：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.aliyunAccessKeyId}" name="aliyunAccessKeyId" placeholder="阿里云AccessKeyId" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3  control-label">AccessKeySecret：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.aliyunAccessKeySecret}" name="aliyunAccessKeySecret" placeholder="阿里云AccessKeySecret" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3  control-label">BucketName：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.aliyunBucketName}" name="aliyunBucketName" placeholder="阿里云BucketName" />
					</div>
				</div>
			</div>
			<div id="qcloud-form" class="${(storageConfig.type == 3)?string('','display-none')}">
				<div class="form-group">
					<div class="col-sm-3  control-label">文件服务器域名：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.qcloudDomain}" name="qcloudDomain" placeholder="腾讯云绑定的域名" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3  control-label">路径前缀：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.qcloudPrefix}" name="qcloudPrefix" placeholder="不设置默认为空" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3  control-label">SecretId：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.qcloudSecretId}" name="qcloudSecretId" placeholder="腾讯云SecretId" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3  control-label">SecretKey：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.qcloudSecretKey}" name="qcloudSecretKey" placeholder="腾讯云SecretKey" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3  control-label">BucketName：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.qcloudBucketName}" name="qcloudBucketName" placeholder="腾讯云BucketName" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-3  control-label">Bucket所属地区：</div>
					<div class="col-sm-9">
						<input type="text" class="form-control" value="${storageConfig.qcloudRegion}" name="qcloudRegion" placeholder="如：sh（可选值 ，华南：gz 华北：tj 华东：sh）" />
					</div>
				</div>
			</div>
		</div>
	</form>
</div>
</@body>
<script type="text/javascript">
	$("input[name=type]").on('ifChecked', function() {
		var ossType = $(this).val();
		if (ossType === "0") {
			$("#local-form").show();
			$("#qiniu-form").hide();
			$("#ali-form").hide();
			$("#qcloud-form").hide();
		} else if (ossType === "1") {
			$("#local-form").hide();
			$("#qiniu-form").show();
			$("#ali-form").hide();
			$("#qcloud-form").hide();
		} else if (ossType === "2") {
			$("#local-form").hide();
			$("#qiniu-form").hide();
			$("#ali-form").show();
			$("#qcloud-form").hide();
		} else if (ossType === "3") {
			$("#local-form").hide();
			$("#qiniu-form").hide();
			$("#ali-form").hide();
			$("#qcloud-form").show();
		}
	});
	function submitHandler() {
		if ($("#storageForm").validate().form()) {
			var formData = $("#storageForm").serialize();
			var index = layer.load(3); // 换了种风格
			$.ajax({
				url : "/system/config/saveStorage",
				type : 'POST',
				dataType : "json",
				data : formData,
				beforeSend : function() {
					$.modal.loading("正在处理中，请稍后...");
					$.modal.disable();
				},
				success : function(data) {
					layer.close(index);
					if (data.code == 200) {
						if (data.msg) {
							parent.layer.msg(data.msg, {
								icon : 1
							});
						} else {
							parent.layer.msg('提交成功', {
								icon : 1
							});
						}
						parent.layer.closeAll('iframe'); // 关闭当前frame
					} else {
						layer.msg(data.msg, {
							icon : 2
						});
						$.modal.closeLoading();
						$.modal.enable();
					}
				}
			});
		}
	}
</script>